import Vue from 'vue'
import VueRouter from 'vue-router'

const Index = () => import('../views/Index'); /* 首页 */
const Forget = () => import('../views/Forget');/* 忘记密码 */
const Today = () => import('../views/Today'); /* 今日 */
const Roster = () => import('../views/Roster');/* 排版 */
const Department = () => import('../views/Department');/* 部门 */
const Data = () => import('../views/Data');/* 数据 */
const Affairs = () => import('../views/Affairs');/* 请假 */
const Setting = () => import('../views/Setting/Setting');/* 设置 */
const WifiSetting = () => import('../views/Setting/WifiSetting');/* wifi设置 */
const LocalSetting = () => import('../views/Setting/LocalSetting');/* 地址设置 */
const HolidaySetting = () => import('../views/Setting/HolidaySetting');/* 公休设置 */
const LeaveSetting = () => import('../views/Setting/LeaveSetting');/* 假期设置 */

Vue.use(VueRouter)

const routes = [
  {
    path: '',
    redirect: '/index'
  },
  {
    path: '/index',
    component: Index
  },
  {
    path: '/forget',
    component: Forget
  },
  {
    path: '/today',
    component: Today
  },
  {
    path: '/roster',
    component: Roster
  },
  {
    path: '/department',
    component: Department
  },{
    path: '/data',
    component: Data
  },{
    path: '/affairs',
    component: Affairs
  },{
    path: '/setting',
    component: Setting,
  },{
    path: '/setting/wifi',
    component: WifiSetting
  },{
    path: '/setting/location',
    component: LocalSetting
  },{
    path: '/setting/holiday',
    component: HolidaySetting
  },{
    path: '/setting/leave',
    component: LeaveSetting
  }
]

const router = new VueRouter({
  routes: routes,
  //mode: 'history',
  base: process.env.BASE_URL,
  routes
})

router.beforeEach((to, from, next) => {
  //debugger
  if (to.path === '/index') {
    next();
  } else if (to.path === '/forget') {
    next();
  }else {
    let token = sessionStorage.getItem('Authorization');
    if (!token) {
      next('/index');
    } else {
      next();
    }
  }
});

export default router
